<template>

	<swiper class="swiper" vertical :duration="300">
		<swiper-item>
			<view class="content" :style="{ backgroundImage: 'url(' + bgUrl + ')' }">
				<!-- 上半部分：标题和副标题 -->
				<view class="top-section">
					<view class="main-title">会议列表</view>
					<view class="subtitle" v-for="(meet, index) in meets" @click="openMeet(meet)">
						{{numberFilter(index+1)}}、{{ meet.meetName }}
					</view>
				</view>
			</view>
		</swiper-item>
	</swiper>
</template>

<script>
	import bg from '@/static/main.jpg';
	import FileJS from "@/utils/File.js";
	export default {
		data() {
			return {
				bgUrl: bg,
				currentDate: this.getFormattedDate(),
				// 假设文件都在 /ycmlMeeting 文件夹中
				meets: [],
			};
		},
		onLoad() {
			plus.device.setWakelock(true);
		},
		onUnload() {
			// 🔴 页面卸载时释放唤醒锁
			plus.device.setWakelock(false);
		},
		mounted() {
			plus.screen.lockOrientation('portrait-primary');

			// 可选：每秒更新一次时间（如果需要动态更新）
			setInterval(() => {
				this.currentDate = this.getFormattedDate();
			}, 1000);
		},
		created() {
			plus.android.requestPermissions([
				'android.permission.WRITE_EXTERNAL_STORAGE',
				'android.permission.READ_EXTERNAL_STORAGE',
				'android.permission.INTERNET',
				'android.permission.ACCESS_WIFI_STATE'
			], e => {
				this.readFN2()
			}, v => {
				uni.showToast({
					title: '失败'
				})
			})
		},
		methods: {
			numberFilter(num) {
				const changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九']
				const unit = ['', '十', '百']
				num = parseInt(num)
				const getWan = (temp) => {
					const strArr = temp.toString().split('').reverse()
					let newNum = ''
					for (var i = 0; i < strArr.length; i++) {
						newNum = (i === 0 && strArr[i] === 0 ? '' : (i > 0 && strArr[i] === 0 && strArr[i - 1] ===
							0 ? '' : changeNum[strArr[i]] + (strArr[i] === 0 ? unit[0] : unit[i]))) + newNum
					}
					return newNum
				}
				const overWan = Math.floor(num / 100)
				let noWan = num % 100
				if (noWan.toString().length < 2) noWan = '0' + noWan
				return overWan ? getWan(overWan) + '百' + getWan(noWan) : getWan(num)
			},
			openMeet(meet) {
				var Environment = plus.android.importClass("android.os.Environment");
				var sdRoot = Environment.getExternalStorageDirectory().getAbsolutePath();
				uni.navigateTo({
					url: '/pages/index/index?meetData=' + JSON.stringify(meet.meetData) + '&isList=1' +
						'&sdRoot=' + sdRoot,
				})
			},
			readFN2() {
				let File = plus.android.importClass("java.io.File");
				let BufferedReader = plus.android.importClass("java.io.BufferedReader");
				let FileReader = plus.android.importClass("java.io.FileReader");
				var Environment = plus.android.importClass("android.os.Environment");
				var sdRoot = Environment.getExternalStorageDirectory().getAbsolutePath();


				let targetFile = new File(sdRoot,
					"/wzhxt_public/unzipped/ycmlMeeting/index.json"); // 这里是你要读取的 JSON 或 TXT 文件路径

				// 获取文件路径
				const filePath = sdRoot + "/wzhxt_public/text_files/meets.txt";
				const meetsContent = JSON.parse(FileJS.readTxt(filePath));

				if (targetFile.exists()) {
					let fileReader = new FileReader(targetFile);
					let bufferedReader = new BufferedReader(fileReader);
					let line;
					let content = "";

					while ((line = bufferedReader.readLine()) !== null) {
						content += line;
					}

					bufferedReader.close();
					fileReader.close();
					// 尝试解析 JSON
					try {
						const meet = JSON.parse(content);
						if (meet.length > 0) {
							for (let a in meet) {
								for (let i in meetsContent) {
									if (meetsContent[i].meetId == meet[a].meetData.meetId) {
										this.meets.push(meet[a])
									}
								}
							}
						}
						if (meetsContent.length === 1) {
							uni.redirectTo({
								url: '/pages/index/index?meetData=' + JSON.stringify(this.meets[0].meetData) +
									'&isList=0',
								animationType: 'none',
								animationDuration: 0
							})
						} else {
							for (let i in meetsContent) {
								if (meetsContent[i].meetId == meet[a].meetData.meetId) {
									this.meets.push(meet[a])
								}
							}
						}
					} catch (e) {
						console.error("JSON 解析失败：", e);
						uni.showToast({
							title: '加载失败，请检查',
						})
					}
				} else {
					console.warn("文件不存在：" + targetFile.getAbsolutePath());
					uni.showToast({
						title: '文件不存在，请检查',
					})
				}

			},
			getFormattedDate() {
				const now = new Date();
				const year = now.getFullYear();
				const month = String(now.getMonth() + 1).padStart(2, '0');
				const day = String(now.getDate()).padStart(2, '0');
				return `${year}年${month}月${day}日`;
			},
		}
	};
</script>

<style>
	@font-face {
		font-family: 'fzxbsjt';
		/* 自定义字体名称 */
		src: url('/static/fonts/fzxbsjt.ttf');
	}

	@font-face {
		font-family: 'fs';
		/* 自定义字体名称 */
		src: url('/static/fonts/fs.ttf');
	}

	@font-face {
		font-family: 'ht';
		/* 自定义字体名称 */
		src: url('/static/fonts/ht.ttf');
	}

	@font-face {
		font-family: 'kt';
		/* 自定义字体名称 */
		src: url('/static/fonts/kt.ttf');
	}
</style>

<style>
	page {
		height: 100%;
		background: #fff;
		color: rgb(38, 38, 38);
		min-height: 100vh;
		position: relative;
		overflow-x: hidden;
	}

	.swiper {
		width: 100vw;
		height: 100vh;
	}

	* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
		font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
	}


	.content {
		display: flex;
		flex-direction: column;
		/* 垂直排列 */
		align-items: left;
		padding: 0 30px 0 30px;
		justify-content: space-between;
		/* 上下两端对齐 */
		width: 100vw;
		height: 100vh;
		background-size: cover;
		background-repeat: no-repeat;
	}

	.top-section {
		height: 70vh;
		text-align: left;
		/* 让标题居中 */
		//margin-top: 350px;
		padding-bottom: 50px;
	}

	.bottom-section {
		height: 30vh;
		width: 100%;
		text-align: center;
		/* 让底部内容居中 */
		margin-bottom: 20px;
		/* 调整底部间距 */
	}

	.bottom-info {
		//font-weight: bold;
		color: black;
		line-height: 1.8rem;
		font-size: 1.8rem;
		text-align: center;
		font-family: 'kt';
		letter-spacing: 0.1em;
		margin: 18px 0;
		/* 调整行间距 */
		//padding-bottom: 50px;
	}

	// .content {
	// 	display: flex;
	// 	align-items: center;
	// 	justify-content: center;
	// 	width: 100vw;
	// 	height: 100vh;
	// 	background-size: cover;
	// 	background-repeat: no-repeat;
	// }

	.content>view {
		margin-bottom: 15rem;
	}

	.main-title {
		color: #fff;
		font-size: 3.0rem;
		font-weight: 700;
		text-align: center;
		font-family: 'fzxbsjt';
		letter-spacing: 0.1em;
		//margin-top: 2250px; /* 增加上外边距 */
		padding-top: 250px; //增加内边距
		padding-bottom: 20px;
	}

	.subtitle {
		white-space: pre-wrap;
		font-weight: bold;
		color: #fff;
		font-size: 2.5rem;
		text-align: left;
		text-indent: 90px;
		font-family: 'fzxbsjt';
		margin: 2.5rem 0;
		letter-spacing: 0.1em;
		/* 字间距调整 */
	}

	.meetingCount {
		//font-weight: bold;
		color: black;
		//line-height: normal;
		//margin-top: 0;        /* 上一行行高为 0 */
		margin-bottom: 45rem;
		/* 下一行行高为 45rem */
		font-size: 1.8rem;
		text-align: center;
		font-family: 'kt';
		letter-spacing: 0.1em;
	}

	.meetingCount2 {
		//font-weight: bold;
		color: black;
		line-height: 2.5rem;
		font-size: 1.8rem;
		text-align: center;
		font-family: 'kt';
		letter-spacing: 0.1em;
		margin: 0.5rem 0 0.8rem;
	}

	.metting-warp {
		width: 100vw;
		height: 100vh;
		padding: 5rem 0
	}

	.warp-title {
		font-size: 3.5rem;
		font-weight: bold;
		text-align: center;
		color: red;
		font-family: 'fzxbsjt';
		margin-top: -0.5rem;
		/* 可选：通过负值上移标题 */
	}

	.warp-content {
		padding: 0 3.5rem 2rem 4.5rem;
	}
</style>